/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.fyx.web.context;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.fyx.linker.web.LinkerLocal;

/**
 *
 * @author xljan
 */
public class WebPage {

    public static void refresh(){
        try {
            Context ctx = new InitialContext();
            LinkerLocal linker = (LinkerLocal)ctx.lookup("java:global/NewFyx/"
                    + "FyxWeb/LinkerBean!org.fyx.linker.web.LinkerLocal");
            String url = WebContext.getRequestURL();
            FacesContext.getCurrentInstance().getExternalContext().redirect(
                    linker.getLink(url));
        } catch (NamingException ex) {
            Logger.getLogger(WebPage.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(WebPage.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public static void redirect(String url){
        try {
            FacesContext.getCurrentInstance().getExternalContext().redirect(url);
        } catch (IOException ex) {
            Logger.getLogger(WebPage.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public static void sendMessage(FacesMessage.Severity severity, String summary, String detail){
        FacesContext.getCurrentInstance().
                addMessage(null, new FacesMessage(severity, summary, detail));
    }
    
    public static void sendMessage(FacesMessage.Severity severity, String summary){
        sendMessage(severity, summary, "");
    }
}
